package com.lxlg.lxlg_order.consumer;

import com.lxlg.lxlg_order.infra.model.OrderLogs;
import com.lxlg.lxlg_order.service.service.OrderLogsService;
import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.apache.rocketmq.spring.core.RocketMQPushConsumerLifecycleListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
@RocketMQMessageListener(consumerGroup = "Order_log",topic = "Order_log")
//打印订单日志
public class OrderLogStateConsumer implements RocketMQListener<OrderLogs>, RocketMQPushConsumerLifecycleListener {
    @Resource
    private OrderLogsService orderLogsService;
    @Override
    public void prepareStart(DefaultMQPushConsumer consumer) {
        consumer.setMaxReconsumeTimes(1);
    }

    @Override
    public void onMessage(OrderLogs message) {
        orderLogsService.save(message);
    }
}
